<template>
  <el-dialog :title="info.title" :visible.sync="visible" center width="660px" :before-close="handleCancel">
    <el-row>
      <el-col :span="24">
        <div id="container" style="width: 620px; height: 400px"></div>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>

export default {
  props: {
    info: {
      type: Object,
      default: null
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  data() {
    return {
      form: {},
      map: false,
      visible: false
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.form = this.info.edit
        this.$nextTick(() => {
          this.initTXDT()
        })
      }
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  mounted() {
  },
  methods: {
    initTXDT() {
      let self = this
      let longitude = this.form.longitude
      let latitude = this.form.latitude
      let center = new TMap.LatLng(latitude, longitude)
      this.map = new TMap.Map("container", {
        rotation: 0,//设置地图旋转角度
        pitch:0, //设置俯仰角度（0~45）
        zoom:16,//设置地图缩放级别
        center: center//设置地图中心点坐标
      })
      let markerLayer = new TMap.MultiMarker({
        id: 'marker-layer',
        map: self.map
      })
      markerLayer.add({
        position: new TMap.LatLng(latitude, longitude)
      })
    },
    handleCancel(done) {
      if (this.$refs['formDate']) this.$refs['formDate'].resetFields()
      if (done && typeof done === Function) {
        done()
      } else {
        this.visible = false
      }
      this.map.destroy()
    }
  }
}
</script>

<style>

</style>
